#!/usr/bin/env python
# -*- coding: utf8 -*-

import os
import sys

reload(sys)
sys.path.append('/etc/fanfan/')
sys.setdefaultencoding('utf8')
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)))

from lib.common.aliyun_ots import cli as OTS, TableMeta, ReservedThroughput, CapacityUnit

tables = [
    # user
    ('login', [('account', 'STRING')]),

    # 兑换码的API
    ('prize', [('exchange_code', 'STRING')])
]

ots = OTS()


def delete_table(table):
    code = ots.delete_table(table)
    print code


def create():
    for table in tables:
        try:
            meta = TableMeta(table[0], table[1])
            reserved_throughput = ReservedThroughput(CapacityUnit(0, 0))
            ots.create_table(meta, reserved_throughput)
        except Exception as e:
            print('{} : {}'.format(table[0], e))


if __name__ == '__main__':
    create()
